package cn.rumoss.nettytest.time.pojo;

import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

public class TimeClientHandler extends ChannelHandlerAdapter{
  
  /**
   * 每当从客户端收到新的数据时,这个方法会在收到消息时被调用
   */
  @Override
  public void channelRead(ChannelHandlerContext ctx,Object msg) throws Exception{
    
    UnixTime date = (UnixTime)msg;
    System.out.println("客户端收到UnixTime: " + date);
    ctx.close();
    
  }
  
  @Override
  public void exceptionCaught(ChannelHandlerContext ctx,Throwable cause) throws Exception{
    
    // 当异常发生的时候关闭连接
    cause.printStackTrace();
    ctx.close();
    
  }
  
}
